<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class User extends CI_Controller {
	/**
	 * Contrust class
	 *
	 * @access public
	 */
     
    protected $_arrParam;
    
	public function __construct(){
		parent::__construct();

        require_once(APPPATH . 'modules/backend/autoload.php');
		$this->load->library('login_manager');
                //$this->load->model('backend/users_model');
		$this->load->language('backend');
		$this->smarty->assign('language', $this->lang);
		$this->smarty->assign('message',$this->session->flashdata('message'));
		$this->smarty->assign('error_message',$this->session->flashdata('error_message'));
                
                $css_files = array(base_url() . 'jscripts/jqxGrid/styles/jqx.base.css');
                $js_files = array(base_url() . 'jscripts/jqxGrid/jqx-all.js');
                $this->smarty->assign('css_files', $css_files);
                $this->smarty->assign('js_files', $js_files);
                      
        require_once(APPPATH . 'modules/backend/denied.php');
	}
	
	function index(){
            $jqxgrid = array();
            
            $jqxtheme = array(base_url() . 'library/jqwidgets/styles/jqx.darkblue.css');
            
            $jqxgrid['url_metadata'] = base_url().($this->router->directory.'user/jqxgrid_jsoninit');

            $jqxgrid_init = $this->smarty->get_contents('backend/js/jqxgrid');
            $js_text = array($jqxgrid_init);
            
            $this->smarty->assign('heading', 'QUẢN LÝ TÀI KHOẢN');
            $this->smarty->assign('jqxtheme', $jqxtheme);
            $this->smarty->assign('js_text', $js_text);
            $this->smarty->assign('title','Admin Panel - Quản lý tài khoản');

            // view
            $this->smarty->view('backend/user/jqxgrid', 'grid');
            $this->smarty->display('backend/admin');
            
            $user = $this->login_manager->get_user();
            $aParamAdminLog=array(
                            'username'   => $user[0]->name,
                            'customerID' => $user[0]->customerID,
                            'email'      => $user[0]->email,
                            'lastLogin'  => date("Y-m-d H:i:s"),
                            'logAction'  => "Quản lý tài khoản : Tất cả tài khoản",
                            'ip'         => $_SERVER['REMOTE_ADDR'],
                            'uID'        => $user[0]->uID 
                            );
            $log = $this->db_user_model->insertUserAdminLog($aParamAdminLog);
	}
	
        function adminusers()
        {
            if(IS_AJAX){
                $result['rows'] = $this->db_user_model->getUserByGroupId('1');
                $result['total_row'] = count($result['rows']);
                echo json_encode($result);
            }
        }
	
	function jqxgrid_jsoninit(){
		if(IS_AJAX){           
			$user['rows'] = $this->db_user_model->getUsers();
                        $user['total_row'] = count($user['rows']);
			echo json_encode($user);
		}
	}
    
    public function adminlog(){
        $jqxgrid = array();
            
        $jqxtheme = array(base_url() . 'library/jqwidgets/styles/jqx.darkblue.css');
        
        $jqxgrid['url_metadata'] = base_url().($this->router->directory.'user/jqxgrid_jsoninit_adminlog');

        $jqxgrid_init = $this->smarty->get_contents('backend/js/jqx_hostility');
        $js_text = array($jqxgrid_init);
        
        $namelog = $this->db_user_model->getUsersAdminlog();
        
        $this->smarty->assign('heading', 'ADMIN LOG');
        $this->smarty->assign('jqxtheme', $jqxtheme);
        $this->smarty->assign('namelog', $namelog);
        $this->smarty->assign('js_text', $js_text);
        $this->smarty->assign('title','Admin Panel - AdminLog');

        // view
        $this->smarty->view('backend/user/jqx_hostility', 'grid');
        $this->smarty->display('backend/admin');
        
        $user = $this->login_manager->get_user();
        $aParamAdminLog=array(
                        'username'   => $user[0]->name,
                        'customerID' => $user[0]->customerID,
                        'email'      => $user[0]->email,
                        'lastLogin'  => date("Y-m-d H:i:s"),
                        'logAction'  => "Quản lý tài khoản : Admin log",
                        'ip'         => $_SERVER['REMOTE_ADDR'],
                        'uID'        => $user[0]->uID   
                        );
        $log = $this->db_user_model->insertUserAdminLog($aParamAdminLog);
        
    }
    
    function jqxgrid_jsoninit_adminlog(){
		if(IS_AJAX){          
			$userlog['rows'] = $this->db_user_model->getAdminLog();
                        $userlog['total_row'] = count($userlog['rows']);
			echo json_encode($userlog);
		}
	}
    
    public function filterlog(){
        $jqxgrid = array();
            
        $jqxtheme = array(base_url() . 'library/jqwidgets/styles/jqx.darkblue.css');
        $jqxgrid['uID'] = $this->input->get('uID');
        $jqxgrid['url_metadata'] = base_url().($this->router->directory.'user/jqxgrid_jsoninit_filterlog?uID='.$jqxgrid['uID']);
        
        $this->smarty->assign('jqxgrid', $jqxgrid);
        
        $jqxgrid_init = $this->smarty->get_contents('backend/js/jqx_filterlog');
        $js_text = array($jqxgrid_init);
        
        $namelog = $this->db_user_model->getUsersAdminlog();
        
        $this->smarty->assign('heading', 'ADMIN LOG');
        $this->smarty->assign('jqxtheme', $jqxtheme);
        $this->smarty->assign('namelog', $namelog);
        $this->smarty->assign('js_text', $js_text);
        $this->smarty->assign('title','Admin Panel - AdminLog');

        // view
        $this->smarty->view('backend/user/jqx_hostility', 'grid');
        $this->smarty->display('backend/admin');
    }
    
    function jqxgrid_jsoninit_filterlog(){
        
        $uID = $this->input->get('uID');
        $userlog['rows'] = $this->db_user_model->getUsersAdminFilterlog($uID);
                    $userlog['total_row'] = count($userlog['rows']);
        echo json_encode($userlog);
	}
}
	
/* End of file user.php */
/* Location: ./system/application/controllers/backend/user.php */